#include "starttypedialog.h"
#include "ui_starttypedialog.h"
#include <unistd.h>
#include <QMessageBox>
#include <QDebug>

StartTypeDialog::StartTypeDialog(int styleId, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::StartTypeDialog)
{
    ui->setupUi(this);
    move(0,0);
    this->setWindowFlags(Qt::FramelessWindowHint);    //无边框
    this->setStyleSheet("outline: none;");            //无虚线框
#ifdef BUILD_ARM
    setGeometry(70,128,460,595);
#endif
}

StartTypeDialog::~StartTypeDialog()
{
    delete ui;
}

void StartTypeDialog::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        this->setGeometry(0,0,600,450);
//        ui->label_companyImage->setGeometry(0,0,600,400);
//        ui->enterWeb_Btn->setGeometry(200,400,200,40);
//        ui->returnBtn->setGeometry(510,400,70,40);
        break;
    default:
        break;
    }
}

void StartTypeDialog::updateView(int type)
{

}

void StartTypeDialog::updateView(QString msg)
{

}

void StartTypeDialog::updateViewShutDown(QString msg)
{
  ui->label_info->setText(msg);
}

void StartTypeDialog::changeLanguage()
{
    ui->retranslateUi(this);
}

void StartTypeDialog::on_sureBtn_clicked()
{
    int type;
    if(true==ui->radioButton_coolstart->isChecked())
    {
       type=0;
    }
    else  if(true==ui->radioButton_hotstart->isChecked())
    {
       type=1;
    }
    else
    {
        type=1;
    }

    emit setStartTypeSignal(type);
    sleep(1);
    emit setShutDownSiganl();


}

void StartTypeDialog::on_cancelBtn_clicked()
{
    this->hide();
}

void StartTypeDialog::on_button_enableShutDown_clicked()
{
    emit controlShutDownEnable(true);
}

void StartTypeDialog::on_button_disableShutDown_clicked()
{
    emit controlShutDownEnable(false);
}

void StartTypeDialog::on_button_shutDownHmi_clicked()
{
    QMessageBox message(QMessageBox::Question, "提示", "是否关闭HMI主机！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    qDebug()<<"shutdown -h now";
    system("shutdown -h now");
}
